package com.ikun.admin.modules.noauth.controller;

import com.ikun.admin.modules.noauth.iservice.ICommonService;
import com.ikun.admin.modules.noauth.vo.DictVo;
import com.ikun.admin.modules.noauth.vo.ForgotPasswordVo;
import com.ikun.admin.modules.noauth.vo.LoginByCodeVo;
import com.ikun.admin.modules.noauth.vo.ReFreshVo;
import com.ikun.common.entity.SecurityUserInfo;
import com.ikun.common.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

/**
 * @ClassName CommonController
 * @Description:
 * @CreateDate: 2024/4/19 17:55
 */
@RestController
@RequestMapping("/noAuth/common")
@Api(tags = "不需要security拦截的通用接口")
public class CommonController {

    @Autowired
    private ICommonService icommonService;

    @PostMapping("/user/updatePassword/API_001")
    @ApiOperation("忘记密码 通过手机号或邮箱修改密码的接口")
    public Result<String> updatePasswordByCode(@RequestBody ForgotPasswordVo forgotPasswordVo) {
        return icommonService.updatePasswordByCode(forgotPasswordVo);
    }

    @GetMapping("/send/code/API_002")
    @ApiOperation("获取验证码接口")
    public Result<String> getCode(@RequestParam String codeNumber, @RequestParam Integer codeType) {
        return icommonService.getCode(codeNumber, codeType);
    }


    @PostMapping("/check/code/API_003")
    @ApiOperation("忘记密码校验验证码")
    public Result<String> checkCode(@RequestBody ForgotPasswordVo forgotPasswordVo) {
        return icommonService.checkCode(forgotPasswordVo);
    }

    @GetMapping("/getImgCode/API_004")
    @ApiOperation("获取图片验证码接口")
    public void getImageCode(HttpServletResponse response, HttpSession session) throws IOException {
        icommonService.getImgCode(response, session);
    }

    @PostMapping("/check/imgCode/API_005")
    @ApiOperation("图片验证码校验接口")
    public Result<String> checkImgCode(@RequestBody ForgotPasswordVo forgotPasswordVo, HttpSession session) {

        return icommonService.checkImgCode(forgotPasswordVo, session);
    }

    @PostMapping("/updatePassword/API_006")
    @ApiOperation("邮箱校验接口")
    public Result<String> updatePassword(@RequestBody ForgotPasswordVo forgotPasswordVo) {
        return icommonService.updatePasswordByCode(forgotPasswordVo);
    }

    @PostMapping("/user/loginByCode/API_007")
    @ApiOperation("验证码登录接口")
    public Result<SecurityUserInfo> loginByCode(@RequestBody LoginByCodeVo loginByCodeVo) {
        return icommonService.loginByCode(loginByCodeVo);
    }

    @PostMapping("/common/check/code/API_008")
    @ApiOperation("通用校验验证码接口")
    public Result<String> commonCheckCode(String codeNumber, Integer codeType, String code) {
        return icommonService.commonCheckCode(codeNumber, codeType, code);
    }

    @GetMapping("/pre/request")
    @ApiOperation("预请求")
    public Result<String> preRequest() {
        return new Result<String>().success();
    }

    @PostMapping("/refresh/token")
    @ApiOperation("刷新token")
    public Result<String>  refreshToken(@RequestBody ReFreshVo reFreshVo){
        return icommonService.refreshToken(reFreshVo);
    }

    @GetMapping("/dict/select/{group}")
    public Result<List<DictVo>> selectDict(@PathVariable String group){
        return icommonService.selectDict(group);
    }
}
